package data;

import java.util.GregorianCalendar;

/**
 * This is an invite for a meeting and is a extended
 * class of Message
 * @author daniel
 */
public class Invite extends Message {
	
	public static final int ANSWER_UNKOWN = 0;
	public static final int ANSWER_YES = 1; 
	public static final int ANSWER_NO = 2; 
	
	private int answer;
		
	public Invite(Meeting meeting) {
		super(meeting);
		answer = Invite.ANSWER_UNKOWN;

	}
	
	public Invite(Meeting meeting, User receiver, String subject, String description, GregorianCalendar sendTime, GregorianCalendar readTime) {
		super(meeting, receiver, subject, description, sendTime, readTime);
		answer = Invite.ANSWER_UNKOWN;
	}
	
	/**
	 * For rejecting the meeting
	 */
	public void reject() {
		answer = Invite.ANSWER_NO;
		changeSupport.firePropertyChange("answer", null, ANSWER_NO);
	}
	
	/**
	 * For accepting the meeting
	 */
	public void accept() {
		answer = Invite.ANSWER_YES;
		changeSupport.firePropertyChange("answer", null, ANSWER_YES);
	}
	
	public int getAnswer() {
		return answer;
	}

	public void setAnswer(int answer) {
		this.answer = answer;
		changeSupport.firePropertyChange("answer", null, answer);
	}
	
	@Override
	public String toString() {
		String string = "";
		string += "Invitasjon til møte: ";
		string += getSubject();
		string += ", " + getDescription();
		string += ", ";
		switch(answer) {
		case ANSWER_NO : string += "takket nei"; break;
		case ANSWER_UNKOWN : string += "ikke svart"; break;
		case ANSWER_YES : string += "takket ja"; break;
		}
		
		string += ", møteleder: " + ((getMeeting() != null) ? getMeeting().getOwner() : "ingen leder");
		
		return string;
	}
}
